#include "Buildings.h"



Buildings::Buildings(int s, TextureDrawer* td){
	size =s;

	for(int i =0;i<100;i++){
		heights[i] = rand()%10+10;
	}

	texture = td;
	showTexture = true;
}

void Buildings::changeShowTexture(){
	showTexture = !showTexture;
}

void Buildings::draw(int trackWidth, int offsetFromDistanceTravelled){
	glPushMatrix();
	//glColor3f(.4,.4,.4);
	//int buildingHeight = 20;//rand()%10 + 10;

	for (int i=offsetFromDistanceTravelled; i<50+offsetFromDistanceTravelled; i++)
	{
		glPushMatrix();
		glColor3f((50-i+offsetFromDistanceTravelled)/40.0,
			(50-i+offsetFromDistanceTravelled)/40.0,
			(50-i+offsetFromDistanceTravelled)/40.0);
		int buildingHeight = heights[i%50];
		glTranslatef(trackWidth/2+size/2,buildingHeight/2,-size/2);
		glTranslatef(0,0,-i*size+1);
		glScalef(size,buildingHeight,size);
		if(showTexture){
			texture->drawTexturedCube(1, 1);
		}
		else{
			glColor3f(0,0,0);
			glutSolidCube (1);
		}
		glTranslatef(0,0,-1);
		glPopMatrix();

	}
	for (int i=offsetFromDistanceTravelled; i<50+offsetFromDistanceTravelled; i++)
	{
		glPushMatrix();
		glColor3f((50-i+offsetFromDistanceTravelled)/40.0,
			(50-i+offsetFromDistanceTravelled)/40.0,
			(50-i+offsetFromDistanceTravelled)/40.0);
		int buildingHeight = heights[i%50+50];
		glTranslatef(-(trackWidth/2+size/2),buildingHeight/2,-size/2);
		glTranslatef(0,0,-i*size);
		glScalef(size,buildingHeight,size);
		if(showTexture){
			texture->drawTexturedCube(1, 1);
		}
		else{
			glColor3f(0,0,0);
			glutSolidCube (1);
		}
		glTranslatef(0,0,-1);
		glPopMatrix();

	}

	glPopMatrix();
}